package cc.mrbird.febs.buss.entity;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class YNConverter implements Converter<String>{
    public static final String MALE = "是";
    public static final String FEMALE = "否";

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String stringValue = cellData.getStringValue();
        if (MALE.equals(stringValue)){
            return "male";
        }else {
            return "female";
        }
    }

    @Override
    public CellData convertToExcelData(String integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if ("1".equals(integer)){
            return new CellData("是");
        }else if ("0".equals(integer)) {
            return new CellData("否");
        }else{
            return new CellData("");
        }
    }
}
